#ifndef _BLOOM_FILTER_H_
#define _BLOOM_FILTER_H_
#include <vector>
#include <bitset>
#include <functional>
template <typename T>
class BFilter {
public:
	BFilter(size_t size, size_t num_hashes) : size(size), num_hashes(num_hashes){
		bitArray.resize(size, false);
	}
	~BFilter() {

	}
	
	void add(const T& element) {
		for (int i = 0; i < num_hashes; ++i) {
			size_t n = hash(element, i);
			bitArray[n % size] = true;
		}
	}

	bool iscontain(const T& element) const{
		for (int i = 0; i < num_hashes; ++i) {
			size_t n = hash(element, i);
			if (!bitArray[n % size]) {
				return false;
			}	
		}
		return true;
	}

private:
	size_t hash(const T& element, size_t i) const{
		using hash = std::hash<T>;
		hash hash_fn;
		return hash_fn(element) + i;
	}
private:
	size_t size;
	size_t num_hashes;
	std::vector<bool> bitArray;
};

#endif // !_BLOOM_FILTER_H_